/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.mode;

import deatax.GameData;
import deatax.LandChangeListener;
import deatax.Player;
import deatax.PopulationChangeListener;
import deatax.ResourceAmount;
import deatax.ResourceChangeListener;
import deatax.ScoreChangeListener;
import deatax.Tile;
import deatax.display.miniboard.RevolutionListener;
import java.util.ArrayList;

/**
 *
 * @author pson
 */
public abstract class GameMode implements RevolutionListener, ResourceChangeListener, PopulationChangeListener, LandChangeListener, ScoreChangeListener {

    protected GameData data;
    protected boolean online;
    protected String desc;
    protected String[] reqs;
    protected String[] reqv;
    protected int pmax = 1;

    public GameMode(GameData data) {
        this.data = data;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String[] getReqs() {
        return reqs;
    }

    public void setArgs(String[] args) {
    }

    public String[] getReqv() {
        return reqv;
    }

    public boolean isOnline() {
        return online;
    }

    public void setOnline(boolean online) {
        this.online = online;
    }

    @Override
    public void revolution(Player p) {
    }

    public abstract ArrayList<Player> getResultOrder();
    
    @Override
    public void resourceChanged(Player p, ResourceAmount r) {
        if (p.getLastProb() != p.getCurrentTurn()) {
            if (r.getResource() == data.getGame().getResource("Money")) {
                if (r.getAmount() < 0) {
                    int prob = p.getProbation();
                    if (prob < pmax) {
                        data.getGui().addMessage(p, "The king is displeased with your leadership. You must bring your balance back to positive or you will be eliminated. You have " + (pmax - prob) + " turn" + (prob == (pmax - 1) ? "" : "s") + ".");
                        p.setProbation(prob + 1);
                        p.setLastProb(p.getCurrentTurn());
                    } else if (prob >= pmax) {
                        data.getGui().addMessage(p, "The king strips you of your land. YOU LOSE.");
                        p.lose();

                    }
                } else {
                    if (p.getProbation() > 0) {
                        data.getGui().addMessage(p, "You have managed to bring your balance back to positive. The king reluctantly lets you on your way.");
                        p.setProbation(0);
                        p.setLastProb(0);
                    }
                }
            }
        }
    }

    @Override
    public void populationChanged(Player p, int total) {
    }

    @Override
    public void landChanged(Player p, Tile t) {
    }

    @Override
    public void scoreChanged(Player p, int score) {
    }
}
